/*!
 @header
 @abstract    ICUser.m
 @discussion  ICUser处理如下问题：
 1、保存并记录当前用户的状态
 2、获取用户的信息，如用户id、用户昵称/名称、手机号码等
 3、判断用户是否登录
 4、用户注销功能
 @updated     2013-04-30ICUser.h
 @author      Fox
 @version     1.0.0
 */

#import "ICUser.h"
#import "AppMacro.h"


@implementation ICUser

//判断用户是否登陆
+ (BOOL)isLogin
{
    id currentUser = [[TMCache sharedCache] objectForKey:CURRENTUSER];
    if(currentUser==nil)
        return NO;    
    else
        return YES;
    
    return YES;
    
}

//注销
+ (void)logoff
{
    [[TMCache sharedCache] removeObjectForKey:CURRENTUSER];
}


//保存和获取
+ (void)saveCurrentUser:(id)dic
{
    [[TMCache sharedCache] setObject:dic forKey:CURRENTUSER];
}

+ (id)getCurrentUser
{
    return [[TMCache sharedCache] objectForKey:CURRENTUSER];
}

//用户信息
+ (NSString *)userId
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSDictionary *currentUser = [NSDictionary dictionaryWithDictionary:[self getCurrentUser]];
    
    NSString *userID = [NSString stringWithFormat:@"%@",[currentUser objectForKey:@"user_id"]];

    
    if (ICIsStringEmpty(userID)) {
        return @"";
    }
    
    return  userID;
}

+ (NSString *)userName
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *userName = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"username"]];
    
    if (ICIsStringEmpty(userName)) {
        return @"";
    }
    
    return  userName;
}



+ (NSString *)mobilePhone
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *phone = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"mobile"]];
    
    if (ICIsStringEmpty(phone)) {
        return @"";
    }
    
    return  phone;
}

+ (NSString *)headerImageUrl
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *headerImageUrl = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"photo"]];
    
    if (ICIsStringEmpty(headerImageUrl)) {
        return @"";
    }
    
    return  headerImageUrl;
}


+ (NSString *)personalitySignature
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *personalitySignature = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"personalitySignature"]];
    
    if (ICIsStringEmpty(personalitySignature))
    {
        return @"";
    }
    return personalitySignature;
}


+ (NSString *)gender
{
    if (NO == [self isLogin]) {
        return @"";
    }

    NSString *gender = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"gender"]];
    if (ICIsStringEmpty(gender))
    {
        return @"";
    }
    return gender;
}


+ (NSString *)country
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *district = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"country"]];
    
    if (ICIsStringEmpty(district))
    {
        return @"";
    }
    return district;
}


+ (NSString *)score
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *score = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"score"]];
    
    if (ICIsStringEmpty(score))
    {
        return @"";
    }
    return score;
}


+ (NSString *)userSid
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *sid = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"sid"]];
    
    if (ICIsStringEmpty(sid))
    {
        return @"";
    }
    return sid;
}

+ (NSString *)is_authened
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *is_authened = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"is_authened"]];
    
    if (ICIsStringEmpty(is_authened))
    {
        return @"";
    }
    return is_authened;
}

+ (NSString *)is_member
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *is_member = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"is_member"]];
    
    if (ICIsStringEmpty(is_member))
    {
        return @"";
    }
    return is_member;
}

+ (NSString *)money
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *money = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"money"]];
    
    if (ICIsStringEmpty(money))
    {
        return @"";
    }
    return money;
}

+ (NSString *)pay_pwd
{
    if (NO == [self isLogin]) {
        return @"";
    }
    
    NSString *pay_pwd = [NSString stringWithFormat:@"%@",[[self getCurrentUser] objectForKey:@"pay_pwd"]];
    
    if (ICIsStringEmpty(pay_pwd))
    {
        return @"";
    }
    return pay_pwd;
}

//鉴权码
+(void)cacheAuthenticationKey:(NSString *)key{
    [[TMCache sharedCache] setObject:key forKey:AKEY];
}

+(NSString *)getAuthenticationKey{
    
    NSString *key = [[TMCache sharedCache] objectForKey:AKEY];
    if (key.length==0) {
        return @"";
    }
    return key;
}

@end
